<?php

namespace Tcnet\Pay\Gateways\Ttpay;

use Tcnet\Pay\Contracts\GatewayInterface;
use Tcnet\Pay\Exceptions\InvalidArgumentException;
use Yansongda\Supports\Collection;

abstract class Gateway implements GatewayInterface
{
    /**
     * Mode.
     *
     * @var string
     */
    protected $mode;

    /**
     * Bootstrap.
     *
     * @author tc-net <tc_net@163.com>
     *
     * @throws InvalidArgumentException
     */
    public function __construct()
    {
        $this->mode = Support::getInstance()->mode;
    }

    /**
     * Pay an order.
     *
     * @author tc-net <tc_net@163.com>
     *
     * @param string $endpoint
     *
     * @return Collection
     */
    abstract public function pay($endpoint, array $payload);

    /**
     * Find.
     *
     * @author tc-net <tc_net@163.com>
     *
     * @param $order
     */
    public function find($order): array
    {
        return [
            'endpoint' => 'query_order',
            'order' => is_array($order) ? $order : ['out_order_no' => $order],
        ];
    }
}
